OpenRoads Designer CONNECT Edition SDK Help

Superelevation assign

Description

  • This is a custom interactive tool for assigning superelevation to a corridor using an alignment
  • The user selects a horizontal alignment on which the corridor and superelevation section should exist, superelevation section is then assigned to corridor.
  • The SuperElevationAssign class which extends DgnElementSetTool which handles different events to interact with UI, the SuperElevationAssign class overrides the events here in this tool.

Remarks

  • This sample code is a part of ManagedSDKExample which you get with SDK installation under "examples" section in SDK installation directory.
  • If you encounter any error while using DgnElementSetTool class, make sure to add a reference to Bentley.DgnDisplayNet.dll by selecting Project > Add Reference or change the projects .csproj file to add reference to this dll .
  • The default dll location will be "C:\Program Files\Bentley\OpenRoads Designer CE 10.11\OpenRoadsDesigner\Bentley.DgnDisplayNet.dll".
  • This code is customized and does not include any form.

Source Code


//Required References
using System.Collections.Generic;
using System;
using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;
using Bentley.CifNET.SDK.Edit;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.CifNET.GeometryModel.SDK.Edit;

namespace ManagedSDKExample
{
    class SuperElevationAssign : DgnElementSetTool
    {
        /*----------------------------------------------------------------------------------------------**/
        /* Write Function | The user is prompted to select a horizontal alignment. 
           * The corridor should be created, and superelevation section should be existed to work this successfully
        /*--------------+---------------+---------------+---------------+---------------+----------------*/

        protected override void OnPostInstall()
        {
            base.BeginPickElements();
            AccuSnap.LocateEnabled = true;
            AccuSnap.SnapEnabled = false;
            base.OnPostInstall();
            NotificationManager.OutputPrompt("Select a horizontal alignment.");
            BeginDynamics();
        }

        protected override bool OnPostLocate(HitPath path, out string cantAcceptReason)
        {
            //checks that hitpath is not null
            if (path == null)
            {
                cantAcceptReason = "HitPath is null.";
                return false;
            }

            //checks that the cursor element is not null
            Element el = path.GetCursorElement();
            if (el == null)
            {
                cantAcceptReason = "There is no element at cursor.";
                return false;
            }

            //checks that the cursor element is a civil element
            if (el.ElementType != MSElementType.Line && el.ElementType != MSElementType.LineString && el.ElementType != MSElementType.ComplexString)
            {
                cantAcceptReason = "This is not a civil element.";
                return false;
            }

            Bentley.CifNET.SDK.ConsensusConnection con = ConsensusConnectionEdit.GetActive();
            if (con == null)
            {
                cantAcceptReason = "There was an error connecting to the Civil SDK model.";
                return false;
            }

            Alignment al = (el.ParentElement == null) ? Alignment.CreateFromElement(con, el) : Alignment.CreateFromElement(con, el.ParentElement);

            if (al == null)
            {
                cantAcceptReason = "This is not a civil element.";
                return false;
            }

            cantAcceptReason = String.Empty;
            return true;
        }

        public static void InstallNewInstance()
        {
            SuperElevationAssign cmd = new SuperElevationAssign();
            cmd.InstallTool();
        }

        protected override bool OnDataButton(Bentley.DgnPlatformNET.DgnButtonEvent ev)
        {
            HitPath hitPath = DoLocate(ev, true, 1);
            if (hitPath == null)
                return false;

            Element element = hitPath.GetHeadElement();
            if (element == null)
                return false;

            ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
            Bentley.CifNET.GeometryModel.SDK.Alignment alignment = Bentley.CifNET.GeometryModel.SDK.Alignment.CreateFromElement(con, element);
            if (alignment == null)
            {
                NotificationManager.OutputPrompt("This is not a horizontal alignment.");
                return false;
            }

            GeometricModel gm = con.GetOrCreateGeometricModel();

            if (gm == null)
            {
                return false;
            }

            Corridor superElevationCorridor = null;
            foreach (Bentley.CifNET.GeometryModel.SDK.Corridor corridor in gm.Corridors)
            {
                if (corridor != null)
                {
                    superElevationCorridor = corridor as Corridor;
                    if (superElevationCorridor.CorridorAlignment == alignment)
                        break;
                }
            }

            SuperElevationSection assignSuperElevationSection = null;
            foreach (Bentley.CifNET.GeometryModel.SDK.SuperElevationSection superElevationSection in con.GetActiveGeometricModel().SuperElevationSections)
            {
                if (superElevationSection != null)
                {
                    List<SuperElevation> superElevationsl = new List<SuperElevation>(superElevationSection.SuperElevations);
                    if (superElevationSection.Alignment == alignment && superElevationsl != null && superElevationsl.Count > 0)
                    {
                        assignSuperElevationSection = superElevationSection;
                        break;
                    }
                }
            }

            if (assignSuperElevationSection == null)
            {
                NotificationManager.OutputPrompt("The alignment does not have SuperElevation Section");
                return false;
            }
            con.StartTransientMode();
            SuperElevation assignSuperElevation = null;
            List<SuperElevation> superElevations = new List<SuperElevation>(assignSuperElevationSection.SuperElevations);
            if (superElevations.Count > 0)
            {
                assignSuperElevation = superElevations[0];
            }
            else
            {
                NotificationManager.OutputPrompt("The SuperElevation Section does not have SuperElevation Lane");
                return false;
            }

            double alignmentLength = alignment.LinearGeometry.Length;

            AssignSuperElevations(superElevationCorridor, assignSuperElevation);

            con.PersistTransients();
            EndDynamics();
            NotificationManager.OutputPrompt("Command complete. Select a new horizontal alignment or pick element selection tool to exit command.");
            return true;
        }

        protected override bool OnResetButton(DgnButtonEvent ev)
        {
            InstallNewInstance();
            return true;
        }

        protected override void OnRestartTool()
        {
            InstallNewInstance();
        }

        public override StatusInt OnElementModify(Element element)
        {
            return Bentley.DgnPlatformNET.StatusInt.Error;
        }

        private void AssignSuperElevations(Bentley.CifNET.GeometryModel.SDK.Corridor superElevationCorridor, SuperElevation assignSuperElevation)
        {

            //Add superelevations to corridor 
            string superPoint = "EOP_R";

            string pivotPoint = "CL";
            int priority = 1;
            double startDistance = superElevationCorridor.StartDistance;
            double endDistance = superElevationCorridor.EndDistance;
            Bentley.CifNET.GeometryModel.SDK.PointControl pointControl = assignSuperElevation.AddPointControl(superPoint, pivotPoint, startDistance, endDistance, priority, superElevationCorridor);
            if (pointControl == null)
                return;
            return;

        }
    }
}